import { http } from '@/utils/http';
import type {
  AddressBookList,
  SubmitAuditData,
  returnSubmitData,
  submitIceBoxData,
  submitTableData,
  tableDate,
  tableId,
  SubmitTaskItem,
} from './types/write';

/**
 * 根据菜单id创建表格id
 * @param MenuId 菜单id
 * @returns
 */
export const createTableIdByMenuId = async (MenuId: string) => {
  return await http<tableId[]>({
    url: '/api/reporting/formList',
    method: 'POST',
    data: {
      unionMenuId: MenuId,
    },
  });
};
/**
 * 根据菜单id创建相对应的表格
 * @param MenuId 菜单id
 * @returns
 */
export const createTableById = async (MenuId: string) => {
  const tableId = await createTableIdByMenuId(MenuId);
  const res = await http<tableDate[]>({
    url: '/api/reporting/writeFormList',
    method: 'POST',
    data: {
      formMainId: BigInt(tableId.data[0].formMainId!).toString(),
    },
  });

  return {
    data: res.data,
    reportingFormOperateId: BigInt(
      tableId.data[0].reportingFormOperateId!,
    ).toString(),
  };
};
/**
 * 表格提交
 * @param data
 * @returns
 */
export const submitTable = async (data: submitTableData) => {
  return await http<returnSubmitData>({
    url: '/api/reporting/saveSubmit',
    method: 'POST',
    data: data,
  });
};
/**
 * 根据审批id，读取详情
 * @param id id
 * @returns returnSubmitData
 */
export const showTableById = async (id: string) => {
  return await http<returnSubmitData>({
    url: '/api/reportingHandle/reportingHandelDetail',
    method: 'POST',
    data: { id },
  });
};

/**
 *  提交冰箱
 */
export const submitIceBox = async (data: submitIceBoxData) => {
  return await http<{
    reportID: number;
  }>({
    url: '/api/form/saveCommonForm',
    method: 'POST',
    data: data,
  });
};
/**
 * 查询通信录
 */
export const queryContactList = async () => {
  return await http<AddressBookList[]>({
    url: '/api/user/addressBookList',
    method: 'POST',
    data: {
      functionPointName: 3,
      module: 4,
      temp: 1,
    },
  });
};

/**
 * 提交审核人
 */
export const submitAudit = async (data: SubmitAuditData) => {
  return await http<{ data: string }>({
    url: '/api/auditWork/updateAudits',
    method: 'POST',
    data: data,
  });
};

/**
 * 提交任务
 */
export const submitTask = async (data: any) => {
  return await http<{ data: string }>({
    url: '/api/work/exeSubmit',
    method: 'POST',
    data: data,
  });
};

// 提交任务事项
export const submitTaskItem = async (data: SubmitTaskItem) => {
  return await http<{ data: string }>({
    url: '/api/work/exeSubmit',
    method: 'POST',
    data: data,
  });
};
